package observer

import "fmt"

type Observer interface {
	getId() int
	notified(status int)
	RegisterToSubject(subject Subject)
	RemoveFromSubject(subject Subject)
}

////////////////////////////////////////////////////////////////
type ObserverImpl1 struct {
	id      int
	subject Subject
}

func CreateObserverImpl1() *ObserverImpl1 {
	res := new(ObserverImpl1)
	res.id = 1
	return res
}

func (ob *ObserverImpl1) getId() int { return ob.id }

func (ob *ObserverImpl1) notified(status int) {
	fmt.Printf("ObserverImpl1: updated! %v\n", status)
}

func (ob *ObserverImpl1) RegisterToSubject(subject Subject) {
	if ob.subject == nil {
		ob.subject = subject
	}
	ob.subject.RegisterObserver(ob)
}

func (ob *ObserverImpl1) RemoveFromSubject(subject Subject) {
	ob.subject.RemoveObserver(ob)
}

////////////////////////////////////////////////////////////////
type ObserverImpl2 struct {
	id      int
	subject Subject
}

func CreateObserverImpl2() *ObserverImpl2 {
	res := new(ObserverImpl2)
	res.id = 2
	return res
}

func (ob *ObserverImpl2) getId() int { return ob.id }

func (ob *ObserverImpl2) notified(status int) {
	fmt.Printf("ObserverImpl2: updated! %v\n", status)
}

func (ob *ObserverImpl2) RegisterToSubject(subject Subject) {
	if ob.subject == nil {
		ob.subject = subject
	}
	ob.subject.RegisterObserver(ob)
}

func (ob *ObserverImpl2) RemoveFromSubject(subject Subject) {
	ob.subject.RemoveObserver(ob)
}
